home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 454 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  57 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: David Olsen <olsen@rational.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Comparison operators and enums
  5. Date: 22 Feb 1996 15:20:51 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9602222305.AA03051@picard.rational.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. Content-Type: text/plain; charset="us-ascii"
  11. X-Original-Date: Thu, 22 Feb 1996 15:05:08 -0800
  12. X-Mailer: exmh version 1.5.3 12/28/94
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMSz6/Uy4NqrwXLNJAQGp9AIAtIhEy0FD2nUlnbDH4UoOOiYF1UY0kQEJ
  15.     t8T+XgSOf/DSwosC3Ucj09pcFB+utgJwDy+E2qKFwNG4a78uR2iYqw==
  16.     =seif
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. Consider the following snippet of code (which actually does arise in 
  20. real code since the given template operator!= is taken directly from 
  21. <utility>):
  22.  
  23. template <class T>
  24. bool operator != (const T &x, const T &y)
  25. {
  26.     return !(x == y);
  27. }
  28.  
  29. enum E { a, b, c };
  30.  
  31. bool f (const E &e1, const E &e2)
  32. {
  33.     return e1 != e2;
  34. }
  35.  
  36.  
  37. How should the compiler interpret "e1 != e2" ?  Should it instantiate 
  38. the template function "operator!=(const E &, const E &)", or should it 
  39. promote x and y to int and use the built-in "operator!=(int, int)" ?
  40.  
  41. As I interpret the first paragraph of 13.3.3 in the April 95 draft, the 
  42. template function is a better match because each of its arguments are 
  43. an exact match, while the built-in operator requires a promotion for 
  44. each argument.  Is this interpretation correct?  If so, is this the 
  45. intention of the committee?
  46.  
  47. --
  48. David Olsen
  49. olsen@rational.com
  50. ---
  51. [ To submit articles: Try just posting with your newsreader.  If that fails,
  52.                       use mailto:std-c++@ncar.ucar.edu
  53.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  54.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  55.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  56. ]
  57.